/*    */ package com.zimbra.cs.redolog.op;
/*    */ 
/*    */ import com.zimbra.common.mailbox.Color;
/*    */ import com.zimbra.common.util.Log;
/*    */ import com.zimbra.cs.mailbox.MailServiceException;
/*    */ import com.zimbra.cs.mailbox.Mailbox;
/*    */ import com.zimbra.cs.mailbox.MailboxManager;
/*    */ import com.zimbra.cs.mailbox.MailboxOperation;
/*    */ import com.zimbra.cs.redolog.RedoLogInput;
/*    */ import com.zimbra.cs.redolog.RedoLogOutput;
/*    */ import com.zimbra.cs.redolog.Version;
/*    */ import java.io.IOException;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ public class CreateTag
/*    */   extends RedoableOp
/*    */ {
/*    */   private int mTagId;
/*    */   private String mName;
/*    */   private long mColor;
/*    */   
/*    */   public CreateTag()
/*    */   {
/* 40 */     super(MailboxOperation.CreateTag);
/* 41 */     this.mTagId = 0;
/* 42 */     this.mColor = 0L;
/*    */   }
/*    */   
/*    */   public CreateTag(int mailboxId, String name, Color color) {
/* 46 */     this();
/* 47 */     setMailboxId(mailboxId);
/* 48 */     this.mTagId = 0;
/* 49 */     this.mName = (name != null ? name : "");
/* 50 */     this.mColor = color.getValue();
/*    */   }
/*    */   
/*    */   public int getTagId() {
/* 54 */     return this.mTagId;
/*    */   }
/*    */   
/*    */   public void setTagId(int tagId) {
/* 58 */     this.mTagId = tagId;
/*    */   }
/*    */   
/*    */   protected String getPrintableData() {
/* 62 */     StringBuffer sb = new StringBuffer("id=").append(this.mTagId);
/* 63 */     sb.append(", name=").append(this.mName).append(", color=").append(this.mColor);
/* 64 */     return sb.toString();
/*    */   }
/*    */   
/*    */   protected void serializeData(RedoLogOutput out) throws IOException {
/* 68 */     out.writeInt(this.mTagId);
/* 69 */     out.writeUTF(this.mName);
/*    */     
/* 71 */     out.writeLong(this.mColor);
/*    */   }
/*    */   
/*    */   protected void deserializeData(RedoLogInput in) throws IOException {
/* 75 */     this.mTagId = in.readInt();
/* 76 */     this.mName = in.readUTF();
/* 77 */     if (getVersion().atLeast(1, 27)) {
/* 78 */       this.mColor = in.readLong();
/*    */     } else
/* 80 */       this.mColor = in.readByte();
/*    */   }
/*    */   
/*    */   public void redo() throws Exception {
/* 84 */     int mboxId = getMailboxId();
/* 85 */     Mailbox mbox = MailboxManager.getInstance().getMailboxById(mboxId);
/*    */     try
/*    */     {
/* 88 */       mbox.createTag(getOperationContext(), this.mName, Color.fromMetadata(this.mColor));
/*    */     } catch (MailServiceException e) {
/* 90 */       String code = e.getCode();
/* 91 */       if (code.equals("mail.ALREADY_EXISTS")) {
/* 92 */         if (mLog.isInfoEnabled())
/* 93 */           mLog.info("Tag " + this.mTagId + " already exists in mailbox " + mboxId);
/*    */       } else {
/* 95 */         throw e;
/*    */       }
/*    */     }
/*    */   }
/*    */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/redolog/op/CreateTag.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */